Ticker

6/recent/ticker-posts

Python subjective question for competitive exam (14)

Q1.Program to find gcd of a number using iterative method.

m=6 n=4 while(n>0): r=n q=m%n m=r n=q print(m) >>> ==================== RESTART: C:/Users/Dell/Desktop/aq.py ==================== 2

Q2.Program to find gcd of a number using recursion.

def gcd(m,n): if(n==0): return(m) else: return(gcd(n,m%n)) print(gcd(4,12)) >>> ==================== RESTART: C:/Users/Dell/Desktop/aq.py ==================== 4



Q3.Program to print pyramid.

for i in range(5): for j in range(0,i+1): print("*", end=" ") print("\r") Output ==================== RESTART: C:/Users/Dell/Desktop/we.py ==================== * * * * * * * * * * * * * * *

Q4.Program to print number and number square from 0 to 9.

def square(a): return(a*a) for i in range(10): print(i,square(i)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/we.py ==================== 0 0 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81

Q5 Program to find area of circle using function.


def areacircle(pi,r): re=pi*r*r return(re) r=int(input("enter radius of circle")) print(areacircle(3.14,r)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/we.py ==================== enter radius of circle2 12.56



Post a Comment

0 Comments